<script type="text/javascript">
$(function(){
	var pg = App.soagov.faceView.ui
		, frm = pg.find(".form")
		, tabs = pg.find('.tabs')
		, infoPl = pg.find('.infoPl')
		, iPmsPl = pg.find('.iPmsPl')
		, iPmsGd = pg.seek('iPmsGd')
		, oPmsPl = pg.find('.oPmsPl')
		, oPmsGd = pg.seek('oPmsGd')
		, onMePl = pg.find('.onMePl')
		, onMeGd = pg.seek('onMeGd')
		, imClPl = pg.find('.imClPl')
		, imClGd = pg.seek('imClGd');
		

	tabs.mac('tabs', {
		tabWidth: 80,
		tabHeight: 32,
		items: [{
			code: 'infoPl',
			title: '基本信息',
			el: infoPl
		},{
			code: 'iPmsPl',
			title: '输入参数',
			el: iPmsPl
		},{
			code: 'oPmsPl',
			title: '输出参数',
			el: oPmsPl
		},{
			code: 'onMePl',
			title: '被依赖项',
			el: onMePl
		},{
			code: 'imClPl',
			title: '实现类',
			el: imClPl
		}]
	}).selectFirst();
	
	iPmsGd.mac('grid', {
		cols : [{
			field: 'code', title : '参数名', width: 140
		},{
			field: 'name', title : '参数中文名', width: 162
		},{
			field: 'type', title : '数据类型', width: 162
		},{
			field: 'len', title : '数据长度', width: 162
		},{
			field: 'memo', title : '描述', width: 162
		},{
			field: 'id', title : '操作', width: 48,
			render: function(r){
				return $('<span class="a">删除</span>').click(function(){
					if (confirm('确实要删除这个参数吗？')){
						$.post(App.ctx + '/face/param/delete.do', {
							id: r.id
						}, function(rs){
							var ro = mac.eval(rs);
							if (ro.success) {
								iPmsGd.load();
							}else {
								mac.alert(ro.data, ro.params);
							}
						})
					}
				});
			}
		}],
		loader: {
			url: App.ctx + '/face/param/list.do',
			params: {
				pageNo: 1, pageSize: 50,
				faceId: pg.params.id, flag: 0
			},
			autoLoad: true
		},
		pagerLength: 10
	});
	
	oPmsGd.mac('grid', {
		cols : [{
			field: 'code', title : '参数名', width: 140
		},{
			field: 'name', title : '参数中文名', width: 162
		},{
			field: 'type', title : '数据类型', width: 162
		},{
			field: 'len', title : '数据长度', width: 162
		},{
			field: 'memo', title : '描述', width: 162
		},{
			field: 'id', title : '操作', width: 48,
			render: function(r){
				return $('<span class="a">删除</span>').click(function(){
					if (confirm('确实要删除这个参数吗？')){
						$.post(App.ctx + '/face/param/delete.do', {
							id: r.id
						}, function(rs){
							var ro = mac.eval(rs);
							if (ro.success) {
								iPmsGd.load();
							}else{
								mac.alert(ro.data, ro.params);
							}
						})
					}
				});
			}
		}],
		loader: {
			url: App.ctx + '/face/param/list.do',
			params: {
				pageNo: 1, pageSize: 50,
				faceId: pg.params.id, flag: 1
			},
			autoLoad: true
		},
		pagerLength: 10
	});
	imClGd.mac('grid', {
		cols : [{
			field: 'impl', title : '名称', width: 500,
			render: function (r) {
				return $('<span class="a"></span>').click(function(){
					if (App.logon.power('face.impl.save')){
						App.open({
							action: 'faceImplEdit',
							ctx:'soagov',
							title: '实现类' + r.impl + '修改',
							model: true,
							params:Object.assign({ faceId: pg.params.id},r)
						},function (){
							imClGd.load();
						})
					}
				}).append(r.impl);
			}
		},{
			field: 'version', title : '版本号', width: 100
		},{
			field: 'id', title : '操作', width: 48,
			render: function(r){
				return $('<span class="a">删除</span>').click(function(){
					if (confirm('确实要删除这个实现类吗？')){
						$.post(App.ctx + '/face/impl/delete.do', {
							id: r.id
						}, function(rs){
							var ro = mac.eval(rs);
							if (ro.success) {
								imClGd.load();
							}else {
								mac.alert(ro.data, ro.params);
							}
						})
					}
				});
			}
		}],
		loader: {
			url: App.ctx + '/face/impl/list.do',
			params: {
				pageNo: 1, pageSize: 50,
			},
			autoLoad: true
		},
		pagerLength: 10
	});
	
	
	iPmsPl.seek('add').click(function(e){
		e.stopPropagation();
		App.open({
			action: 'faceParam',
			ctx:'soagov',
			title: '添加输入参数',
			model: true,
			params: { faceId: pg.params.id, flag: 0 }
		}, function(){
			iPmsGd.load();
		});
	});
	oPmsPl.seek('add').click(function(e){
		e.stopPropagation();
		App.open({
			action: 'faceParam',
			ctx:'soagov',
			title: '添加输出参数',
			model: true,
			params: { faceId: pg.params.id, flag: 1 }
		}, function(){
			oPmsGd.load();
		});
	});
	imClPl.seek('add').click(function(e) {
		e.stopPropagation();
		App.open({
			action: 'faceImplEdit',
			ctx:'soagov',
			title: '添加实现类',
			model: true,
			params:{ faceId: pg.params.id}
		},function (){
			imClGd.load();
		})
	})
	
	onMeGd.mac('grid', {
		cols : [{
			field: 'code', title : '编号', width: 140
		},{
			field: 'name', title : '名称', width: 160
		},{
			field: 'impl', title : '实现', width: 160
		},{
			field: 'status', title : '状态', width: 60,
			render: function(r){
				return Cache.base.face.status[r.status];
			}
		},{
			field: 'type', title : '类型', width: 80
		},{
			field: 'ver', title : '组件版本', width: 60
		},{
			field: 'memo', title : '备注', width: 200
		}],
		loader: {
			url: App.ctx + '/com/list.do',
			params: { pageNo: 1, pageSize: 50, faceId: pg.params.id },
			autoLoad: true
		},
		pagerLength: 10
	});

	function adjust(){
		var h, w = pg.width();
		if (pg.params.box) {
			w -= 8;
			h = pg.height() - pg.children('.head').height();
			pg.children('.body').height(h);
			h -= 16;
		} else {
			w = pg.parent().width() - frm.width();
			h = pg.parent().height();
			pg.height(h-30);
		}
		tabs.height(h-30);
		tabs.width(window.innerWidth-310);
		tabs.adjust();
		h = tabs.children('.body').height();
		
		var d = iPmsPl.children('.head').height() + 26;
		iPmsGd.parent().height(h - d);
		iPmsGd.adjust();
		oPmsGd.parent().height(h - d);
		oPmsGd.adjust();
		onMeGd.parent().height(h - d);
		onMeGd.adjust();
		imClGd.parent().height(h - d);
		imClGd.adjust();
	}
	$(window).resize(adjust);
	adjust();

	var w = mac.wait('Loading');
	try {
		$.get(App.ctx + '/face/get.do', {
			id: pg.params.id
		}, function(rs) {
			var ro = mac.eval(rs);
			if (ro.success) {
				var o = ro.data;
				frm.seek('code').text(o.code);
				frm.seek('name').text(o.name);
				frm.seek('face').text(o.face);
				frm.seek('entry').text(o.entry);
				frm.seek('ver').text(o.ver);
				frm.seek('status').text(Cache.base.face.status[o.status]);
				var op = $('<span class="a"></span>');
				if (o.status == 0) {
					op.click(function(){
						alert('接口暂未提供');
					}).append('启用');
				} else {
					op.click(function(){
						
					}).append('停用');
				}
				frm.seek('opt').append(op);
				frm.seek('memo').text(o.memo);
			} else {
				mac.alert(ro.data, ro.params);
			}
		});
	} finally {
		w.close();
	}
});
</script>
<div class="tabs"></div>
<div class="infoPl">
	<div class="form">
		<div class="item">
			<span class="label">英文名：</span> <span class="value" name="code"></span>
		</div>
		<div class="item">
			<span class="label">中文名：</span> <span class="value" name="name"></span>
		</div>
		<div class="item">
			<span class="label">接口声明：</span> <span class="value" name="face"></span>
		</div>
		<div class="item">
			<span class="label">入口方法：</span> <span class="value" name="entry"></span>
		</div>
		<div class="item">
			<span class="label">版本：</span> <span class="value" name="ver"></span>
		</div>
		<div class="item">
			<span class="label">状态：</span> <span class="value" name="status"></span>
		</div>
		<div class="item">
			<span class="label">操作：</span>
			<div class="value" name="opt"></div>
		</div>
		<div class="item">
			<span class="label">描述：</span> <span class="memo" name="memo"></span>
		</div>
	</div>
</div>
<div class="iPmsPl pmsPl">
	<div class="head">
		<button name="add">添加输入参数</button>
	</div>
	<div class="body">
		<div class="grid" name="iPmsGd"></div>
	</div>
</div>
<div class="oPmsPl pmsPl">
	<div class="head">
		<button name="add">添加输出参数</button>
	</div>
	<div class="body">
		<div class="grid" name="oPmsGd"></div>
	</div>
</div>
<div class="onMePl">
	<div class="head">当前接口被以下组件或服务引用</div>
	<div class="body">
		<div class="grid" name="onMeGd"></div>
	</div>
</div>
<div class="imClPl">
	<div class="head">
		<button name="add">添加实现类</button>
	</div>
	<div class="body">
		<div class="grid" name="imClGd"></div>
	</div> 
</div>
